package com.hjqjl.module_home.ui.custom;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;

import com.hjqjl.module_home.databinding.HomeActivityGame2048Binding;
import com.hjqjl.module_home.widget.view2048.Game2048Layout;
import com.hjqjl.whapplib.base.BaseActivity;


/**
 * wh 创建时间：2017/6/9 11:11
 * 2048游戏控件
 * 参考http://blog.csdn.net/lmj623565791/article/details/40020137
 */

public class Game2048Activity extends BaseActivity<HomeActivityGame2048Binding> {
    public static void start(Context context) {
        Intent intent = new Intent(context, Game2048Activity.class);
        context.startActivity(intent);
    }

    @Override
    public void initData() {
        setTitle("自定义控件游戏2048");
    }

    @Override
    public void initListener() {
        pVBinding.homeViewGame2048Game2048Layout.setOnGame2048Listener(new Game2048Layout.OnGame2048Listener() {
            @Override
            public void onScoreChange(int score) {
                pVBinding.homeTvGame2048Score.setText("SCORE: " + score);
            }

            @Override
            public void onGameOver() {
                new AlertDialog.Builder(pContext).setTitle("GAME OVER")
                        .setMessage("YOU HAVE GOT " + pVBinding.homeTvGame2048Score.getText())
                        .setPositiveButton("RESTART", (dialog, which) -> pVBinding.homeViewGame2048Game2048Layout.restart())
                        .setNegativeButton("EXIT", (dialog, which) -> finish()).show();
            }
        });
    }
}
